package com.webfinal.backsystem.controller;

import com.webfinal.backsystem.request.user.*;
import com.webfinal.backsystem.response.user.*;
import com.webfinal.backsystem.service.ManagerService;
import com.webfinal.backsystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ManagerService managerService;

    @RequestMapping(value = "/api/user/login", consumes = "application/json")
    public LoginResponse login(@RequestBody LoginRequest request) {
        return userService.login(request);
    }

    @RequestMapping(value = "/api/user/register")
    public RegisterResponse register(@RequestBody RegisterRequest request) {
        RegisterResponse response=userService.register(request);
        return response;
    }

    @RequestMapping(value = "/api/user/updateinfo")
    public UpdateInfoResponse updateInfo(@RequestBody UpdateInfoRequest request) {
        UpdateInfoResponse response=userService.updateInfo(request);
        return response;
    }

    @RequestMapping(value = "/api/user/adduser")
    public RegisterResponse alluserRegister(@RequestBody AllUserRegisterRequest allUserRegisterRequest) {
        RegisterResponse response = managerService.addUser(allUserRegisterRequest);
        return response;
    }

    @RequestMapping(value = "/api/user/deleteuser")
    public DeleteResponse deleteuser(@RequestBody DeleteRequest request){
        DeleteResponse response = managerService.deleteUser(request);
        return response;
    }

    @RequestMapping(value="/api/user/userlist")
    public UserListResponse userList(){
        UserListResponse response = managerService.userList();
        return response;
    }

    @RequestMapping(value= "/api/user/updatepassword")
    public UpdateInfoResponse updatePassword(@RequestBody UpdateInfoRequest updateInfoRequest){
        System.out.println(updateInfoRequest);
        UpdateInfoResponse response = managerService.updatePassword(updateInfoRequest);
        return response;
    }
}
